from collections import Counter
from utils import *

class Booster:
    def __init__(self):
        self.relics_type_list=[]
        self.triggers={'burst':[]}
        self.start_trig_list=[]
        self.dynamic_list=[]

    def regist_trigger(self, tri_dict):
        self.triggers[tri_dict['trigger']].append(tri_dict)

    def boost_prop(self, blk, key, pdata):
        exec(prop_boost_dict[key])

    def boost_ex(self, blk, bst_list):
        for item in bst_list:
            if 'script' in item:
                exec(item['script'])
            elif 'trigger' in item:
                self.regist_trigger(item)
            elif 'dynamic' in item:
                self.dynamic_list.append(item)


    def boost_dynamic(self, blk, player, enemy):
        for item in self.dynamic_list:
            if eval(item['cond']):
                exec(item['script'])

    def boost_relics(self, blocks, relics_group):
        type_count=dict(Counter([x.type for x in relics_group])) # [int]

        #属性提升
        #bst=lambda cmd,blk,pdata:exec(cmd)
        for relics in relics_group:
            for k,v in relics.properties.items():
                self.boost_prop(blocks, k, v)

        #套装效果
        #bst = lambda cmd, blk: exec(cmd)
        for k,v in type_count.items():
            if v>=4:
                self.boost_ex(blocks, self.relics_type_list[k]['4'])
            elif v>=2:
                self.boost_ex(blocks, self.relics_type_list[k]['2'])

    def boost_weapon(self, blocks, weapon):
        blocks.damage.atk.const+=weapon.base_atk
        self.boost_prop(blocks, weapon.attr.keys()[0], weapon.attr.values()[0])
        self.boost_ex(blocks, weapon.skill)